<%@page import="com.mysql.jdbc.Util"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8" import="java.util.*,java.io.*"%>
<%@ page import="com.oreilly.servlet.MultipartRequest"%>
<%@ page import="com.oreilly.servlet.multipart.*"%>
<%@ page import="com.kctvjeju.web.common.util.BsFileRenamePolicy"%>
<%
	String encType = "UTF-8";
	int maxSize = 1024 * 1024 * 10;
	//upload/년/월/일/아이디/파일네임
	//String saveFolder = "upload"; //파일 저장 폴더 이름 
	String saveFolder = "archive";  
	//ServletContext context = getServletContext();
	//String realFolder = context.getRealPath(saveFolder);
	String realFolder = "/var/www/html/UPLOAD/" + saveFolder;
	
	File file = new File(realFolder);
	String name, filename, original, type, value, path;
	if (!file.exists())
		file.mkdir();

	try {
		MultipartRequest multi = null;
		multi = new MultipartRequest(request, realFolder, maxSize,
		encType, new BsFileRenamePolicy());

		@SuppressWarnings("unchecked")
		Enumeration params = multi.getParameterNames();

		while (params.hasMoreElements()) {
	name = (String) params.nextElement();
	value = multi.getParameter(name);
		}

		@SuppressWarnings("unchecked")
		Enumeration files = multi.getFileNames();

		/*
		out.println("파라미터 이름 : " + name + "<BR>");
		out.println("실제 파일 이름 : " + original + "<BR>");
		out.println("저장된 파일 이름 : " + filename + "<BR>");
		out.println("파일 타입 : " + type + "<BR>");
		 */
		 
		while (files.hasMoreElements()) {
	name = (String) files.nextElement();
	filename = multi.getFilesystemName(name);
	original = multi.getOriginalFileName(name);
	type = multi.getContentType(name);
	file = multi.getFile(name);
	if (file != null) {
		//path = new String("/" + saveFolder + "/" + filename);
		path = new String(realFolder + "/" + filename);
		request.setAttribute("f_path", path);
		request.setAttribute("upload_path", realFolder);
		request.setAttribute("f_original", original);
		request.setAttribute("f_tmb", filename);
		request.setAttribute("f_type", type);
		request.setAttribute("f_size", file.length());
%>
<jsp:forward page="file.jsp" />
<%
	}
		}

	} catch (Exception e) {
		System.out.println(e);
		request.setAttribute("error", "첨부 용량을 초과하였습니다.");
		%>
		<jsp:forward page="file.jsp" />
		<%
	} finally {
	}
%>
